import { Inject, Provide } from '@midwayjs/core';
import { BaseService } from '@cool-midway/core';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { Repository } from 'typeorm';
import { MallGoodsEntity } from '../entity/goods';
import { CoolCommException } from '@cool-midway/core';

/**
 * 商品信息
 */
@Provide()
export class MallGoodsService extends BaseService {
  @InjectEntityModel(MallGoodsEntity)
  mallGoodsEntity: Repository<MallGoodsEntity>;

  /**
   * 检查商品是否存在
   * @param goodsId
   */
  async checkGoodsExists(goodsId: number) {
    const goods = await this.mallGoodsEntity.findOneBy({ id: goodsId });
    if (!goods) {
      throw new CoolCommException('商品不存在');
    }
  }
}
